/* 
 * Gneat (http://gneat.org)
 *
 * (C) Copyright 2011 and beyond - Claudio Stella, all rights reserved.
 *
 * This file is part of Gneat.
 *
 * Gneat is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License (LGPL)
 * as published by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Gneat is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * and the GNU General Public License, for completeness, along with Gneat.  
 * If not, see <http://www.gnu.org/licenses/>.
 */
package org.neatshell.gneat.client.tool;

public class MiscUtils {
	/**
	 * Utility method that given a negative index translate it to the 0-based 
	 * one according with the given length. It assumes that: 
	 * -1 = last = length-1
	 * -length = first.
	 * 
	 * @param index the index to translate
	 * @param length the length of the collection
	 * @return 0-based index if valid arguments are provided, -1 otherwise.
	 */
	public static int getZeroBased(Integer index, Integer length) {
		if (index == null || length == null) return -1;
		if (index >= 0 && index < length) return index;
		else if (index < 0 && length >= 1 && index+length >= 0) return index+length;
		return -1;
	}

//	public static String sanitize(String html) {
//		return SimpleHtmlSanitizer.sanitizeHtml(html).asString();
//	}
	
//	public boolean is(Integer i) {
//		return (i != null);
//	}
//	
//	public boolean is(Boolean b) {
//		return (b != null);
//	}
//	
//	public boolean is(IPresenterList list) {
//		return list != null;
//	}
//	
//	public boolean is(IPresenter presenter) {
//		return presenter != null && presenter.is();
//	}
//
//	public boolean are(IPresenter... items) {
//		return items != null;
//	}	
}